/*
 * @Author: your name
 * @Date: 2022-01-06 08:32:12
 * @LastEditTime: 2022-01-12 08:35:57
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \elementui\src\router\index.js
 */
import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";
import Login from "../views/Login1.vue";
import Slot from "../views/Slot.vue"

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "Home",
    redirect:"/home/all",
    component: Home,
  },
  {
    path:"/zujian",
    name:"Zujian",
    component:()=>import("../views/zujian")
  },
  {
    path:"/animate",
    name:"Animate",
    component:()=>import("../views/Animate")
  },
  {
    path:"/slot",
    name:"Slot",
    component:Slot
  },
  {
    path: "/home",
    name: "Home1",
    component: Home,
    children:[
      {
        path:"all",
        component:()=>import("../components/All.vue")
      },
      {
        path:"userlist",
        component:()=>import("../components/Userlist.vue")
      },
      {
        path:"hao",
        component:()=>import("../components/Hao.vue")
      }
    ]
  },
  {
    path:"/login",
    name:"Login",
    component:Login,
  },
  {
    path: "/about",
    name: "About",
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/About.vue"),
  },
];

const router = new VueRouter({
  routes,
});

router.beforeEach((to,from,next)=>{
    let token=localStorage.getItem("token");
    console.log(token);
    if(to.path==="/login"){
      next();
    }else{
      if(token&&localStorage.getItem("token")==="上海"){
        // 有权限就可以直接进行下一步
        next()
      }else{
        // 没有权限就去获取权限
        // next({path:"/login"})
        next({name:"Login"})
      }
    }
});
router.afterEach((to)=>{
  document.title=to.name||"这是初始的样式页面";
})

export default router;
